package com.zq.it.dao.impl.exam;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zq.it.dao.exam.TTaskDAO;
import com.zq.it.dao.impl.BaseDao;
import com.zq.it.pojo.exam.TTask;

public class TTaskDAOImpl extends BaseDao<TTask> implements TTaskDAO {

	private static final Logger log = LoggerFactory
			.getLogger(TTaskDAOImpl.class);
	// property constants
	public static final String TASK_NAME = "taskName";
	public static final String CASE_TYPE = "caseType";
	public static final String TASK_USER_COUNT = "taskUserCount";
	public static final String TASK_MESSAGE = "taskMessage";
	public static final String EXTEND_FIELD = "extendField";

	@Override
	public void save(TTask transientInstance) {
		log.debug("saving TTask instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public void delete(TTask persistentInstance) {
		log.debug("deleting TTask instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	@Override
	public TTask findById(Long id) {
		log.debug("getting TTask instance with id: " + id);
		try {
			TTask instance = (TTask) getHibernateTemplate()
					.get("com.zq.it.pojo.exam.TTask", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@Override
	public List findByExample(TTask instance) {
		log.debug("finding TTask instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TTask instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TTask as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	public List findByTaskName(Object taskName) {
		return findByProperty(TASK_NAME, taskName);
	}

	@Override
	public List findByCaseType(Object caseType) {
		return findByProperty(CASE_TYPE, caseType);
	}

	@Override
	public List findByTaskUserCount(Object taskUserCount) {
		return findByProperty(TASK_USER_COUNT, taskUserCount);
	}

	@Override
	public List findByTaskMessage(Object taskMessage) {
		return findByProperty(TASK_MESSAGE, taskMessage);
	}

	@Override
	public List findByExtendField(Object extendField) {
		return findByProperty(EXTEND_FIELD, extendField);
	}

	@Override
	public List findAll() {
		log.debug("finding all TTask instances");
		try {
			String queryString = "from TTask";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	@Override
	public void update(TTask instance) {
		log.debug("attaching dirty TTask instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@Override
	public List findByHql(String hql) {
		log.debug("finding TTask instances by Hql");
		try {
			return getHibernateTemplate().find(hql);
		} catch (RuntimeException re) {
			log.error("find by Hql failed", re);
			throw re;
		}
	}

}